<?php
/**
 * 百度地图相关业务封装
 */

class Map {

    /**
     * 根据地址获取经纬度
     * @param $address
     */
    public static function getLngLat($address)
    {
        //http://api.map.baidu.com/geocoder/v2/?address=北京市海淀区上地十街10号&output=json&ak=E4805d16520de693a3fe707cdc962045&callback=showLocation
        if (!$address){
            return '';
        }
        $data=[
            'address' =>$address,
            'ak' =>config('map.ak'),
            'output' =>'json'
        ];
        $url=config('map.baidu_map_url').config('map.geocoder').'?'.http_build_query($data);
        $res=doCurl($url);
        if($res){
            return json_decode($res,true);
        }else{
            return [];
        }
    }

    //http://api.map.baidu.com/staticimage/v2
    /**
     * 根据经纬度或地址获取百度地图
     * @param $center
     * @return mixed
     */
    public static function staticimage($center)
    {
        //http://api.map.baidu.com/geocoder/v2/?address=北京市海淀区上地十街10号&output=json&ak=E4805d16520de693a3fe707cdc962045&callback=showLocation
        if (!$center){
            return '';
        }
        $data=[
            'ak' =>config('map.ak'),
            'width' =>config('map.width'),
            'height' =>config('map.height'),
            'center' =>$center,
            'markers' =>$center,
        ];
        $url=config('map.baidu_map_url').config('map.staticimage').'?'.http_build_query($data);
        $res=doCurl($url);
        return $res;
    }
}
